#include <iostream>
#include <fstream>
using namespace std;

struct Person{
	char name[20];
	int age;
};

void store();
void restore();

int main(){
	store();
	restore();
}

void store(){
	Person p;
	p.name[0] = 'h';
	p.name[1] = 'i';
	p.name[2] = 0;
	
	p.age = 12;

	fstream out("person.dat", ios::out | ios::binary);
//	out.write((char*)(&p), sizeof(Person));
	out.write(reinterpret_cast<char*>(&p), sizeof(Person));
	out.flush();
	out.close();

	cout << "store person to dat\n";
}

void restore(){
	Person *p = new Person;

	fstream in("person.dat", ios::in | ios::binary);
//	in.read((char*)(&p), sizeof(Person));
	in.read(reinterpret_cast<char*>(p), sizeof(Person));
	in.close();

	cout << p->name << ' ' << p->age << '\n';

	cout << "restore person from dat\n";
}
